package com.sinog.biz.service.api.async;

import com.sinog.biz.util.CodeUrlUtils;
import com.sinog.biz.util.JdbcUtils;
import com.sinog.core.utilbean.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * @desc 跨省业务协调、核查数据、二次衔接失败同步、转入原侦查机关、户籍迁入迁出、双列管
 * @author lzq
 * @date 2020-07-05 9:39 下午
 */
@Component
@Slf4j
public class AsyncTask {

    @Autowired
    @Qualifier("middleJdbcTemplate")
    private JdbcTemplate middleJdbcTemplate;

    /**
     * 异步向第三省份同步数据 - 跨省业务协调用
     * @param priNum priNum
     * @param code code
     */
    @Async("taskAsync01-")
    public void send(String priNum,String code) {
        String localCode = CodeUrlUtils.getLocalCode();
        String xtjcKsywxtDeleteSql = "delete from xtjc_ksywxt where pri_num='" + priNum + "'";
        String prisonerMainDeleteSql = "delete from prisoner_main where pri_num='" + priNum + "'";
        String prisaveTempDeleteSql = "delete from prisave_temp where pri_num='" + priNum + "'";
        String prisonerFxDeleteSql = "delete from prisoner_fx where pri_num='" + priNum + "'";
        String prisonerHcDeleteSql = "delete from prisoner_hc where pri_num='" + priNum + "'";
        String prisonerSrDeleteSql = "delete from prisoner_sr where pri_num='" + priNum + "'";
        String prisonerZnDeleteSql = "delete from prisoner_zn where pri_num='" + priNum + "'";
        String prisonerZzDeleteSql = "delete from prisoner_zz where pri_num='" + priNum + "'";
        String uploadAppendixFileDeleteSql = "delete from upload_appendix_file where pri_num='" + priNum + "'";
        String prisonersJxjsDeleteSql = "delete from prisoners_jxjs where pri_num='" + priNum + "'";
        String prisonersZyjnDeleteSql = "delete from prisoners_zyjn where pri_num='" + priNum + "'";
        String prisonerCjpgDeleteSql = "delete from prisoner_cjpg where Pri_num='" + priNum + "'";
        String prisonerXjxxDeleteSql = "delete from prisoner_xjxx where pri_num='" + priNum + "'";
        String prisonerTsDeleteSql = "delete from prisoner_ts where pri_num='" + priNum + "'";
        String prisonerTransferDeleteSql = "delete from prisoner_transfer where pri_num='" + priNum + "'";
        String middleSql = JdbcUtils.createMiddleSql(priNum,xtjcKsywxtDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql);
        String middleSql1 = JdbcUtils.createMiddleSql(priNum,prisonerMainDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql1);
        String middleSql2 = JdbcUtils.createMiddleSql(priNum,prisaveTempDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql2);
        String middleSql3 = JdbcUtils.createMiddleSql(priNum,prisonerFxDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql3);
        String middleSql4 = JdbcUtils.createMiddleSql(priNum,prisonerHcDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql4);
        String middleSql5 = JdbcUtils.createMiddleSql(priNum,prisonerSrDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql5);
        String middleSql6 = JdbcUtils.createMiddleSql(priNum,prisonerZnDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql6);
        String middleSql7 = JdbcUtils.createMiddleSql(priNum,prisonerZzDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql7);
        String middleSql8 = JdbcUtils.createMiddleSql(priNum,uploadAppendixFileDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql8);
        String middleSql10 = JdbcUtils.createMiddleSql(priNum,prisonersJxjsDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql10);
        String middleSql11 = JdbcUtils.createMiddleSql(priNum,prisonersZyjnDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql11);
        String middleSql12 = JdbcUtils.createMiddleSql(priNum,prisonerCjpgDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql12);
        String middleSql13 = JdbcUtils.createMiddleSql(priNum,prisonerXjxxDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql13);
        String middleSql14 = JdbcUtils.createMiddleSql(priNum,prisonerTsDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql14);
        String middleSql15 = JdbcUtils.createMiddleSql(priNum,prisonerTransferDeleteSql,Constants.Number.NUM_ZERO,localCode,code);
        middleJdbcTemplate.update(middleSql15);
        List<String> xtjcKsywxtInsertSql = JdbcUtils.getInsertSql("xtjc_ksywxt","pri_num",priNum,null,null,null,null);
        List<String> prisonerMainInsertSql = JdbcUtils.getInsertSql("prisoner_main","pri_num",priNum,null,null,null,null);
        List<String> prisaveTempinsertSql = JdbcUtils.getInsertSql("prisave_temp","pri_num",priNum,null,null,null,null);
        List<String> prisonerFxinsertSql = JdbcUtils.getInsertSql("prisoner_fx","pri_num",priNum,null,null,null,null);
        List<String> prisonerHcinsertSql = JdbcUtils.getInsertSql("prisoner_hc","pri_num",priNum,null,null,null,null);
        List<String> prisonerSrinsertSql = JdbcUtils.getInsertSql("prisoner_sr","pri_num",priNum,null,null,null,null);
        List<String> prisonerZninsertSql = JdbcUtils.getInsertSql("prisoner_zn","pri_num",priNum,null,null,null,null);
        List<String> prisonerZzinsertSql = JdbcUtils.getInsertSql("prisoner_zz","pri_num",priNum,null,null,null,null);
        List<String> uploadAppendixFileInsertSql = JdbcUtils.getInsertSql("upload_appendix_file","pri_num",priNum,null,null,null,null);
        List<String> prisonersJxjsInsertSql = JdbcUtils.getInsertSql("prisoners_jxjs","pri_num",priNum,null,null,null,null);
        List<String> prisonersZyjnInsertSql = JdbcUtils.getInsertSql("prisoners_zyjn","pri_num",priNum,null,null,null,null);
        List<String> prisonerCjpgInsertSql = JdbcUtils.getInsertSql("prisoner_cjpg","pri_num",priNum,null,null,null,null);
        List<String> prisonerXjxxInsertSql = JdbcUtils.getInsertSql("prisoner_xjxx","pri_num",priNum,null,null,null,null);
        List<String> prisonerTsInsertSql = JdbcUtils.getInsertSql("prisoner_ts","pri_num",priNum,null,null,null,null);
        List<String> prisonerTransferInsertSql = JdbcUtils.getInsertSql("prisoner_transfer","pri_num",priNum,null,null,null,null);
        for(String sql : xtjcKsywxtInsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
        for(String sql : prisonerMainInsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
        for(String sql : prisaveTempinsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
        for(String sql : prisonerFxinsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
        for(String sql : prisonerHcinsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
        for(String sql : prisonerSrinsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
        for(String sql : prisonerZninsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
        for(String sql : prisonerZzinsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
        for(String sql : uploadAppendixFileInsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
        for(String sql : prisonersJxjsInsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
        for(String sql : prisonersZyjnInsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
        for(String sql : prisonerCjpgInsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
        for(String sql : prisonerXjxxInsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
        for (String sql : prisonerTsInsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
        for (String sql : prisonerTransferInsertSql) {
            String isql = JdbcUtils.createMiddleSql(priNum,sql,Constants.Number.NUM_ZERO,localCode,code);
            middleJdbcTemplate.update(isql);
        }
    }
}